package com.share.design.flyweight;

import java.util.HashMap;

/**
 * author:caifan
 * date:2020/2/6
 */
public class FlyweightFactory {
    private HashMap<String, Flyweight> flyweightMap = new HashMap<>();

    public Flyweight getFlyweight(String key) {
        Flyweight flyweight = flyweightMap.get(key);
        if (null != flyweight) {
            System.out.println("具体享元：" + key + "已存在");
        } else {
            flyweight = new ConcreteFlyweight(key);
            flyweightMap.put(key, flyweight);
        }
        return flyweight;
    }
}
